package org.niu.structure;

import java.util.HashMap;
import java.util.Map;

public class LRU {
    private static DoubleLink<Integer> link = new DoubleLink<>();
    private static int[] ans;
    private static int i = 0;
    public int[] LRU (int[][] operators, int k) {
        // write code here
        ans = new int[k];
        for(int[] op:operators){
            if(op[0] == 1){
                set(k,op[1],op[2]);
            }else if(op[0] == 2){
                get(k,op[1]);
            }
        }
        return ans;
    }
    static void set(int k,int index,int value){
        if(link.size() >= k){
            link.deleteLast();
        }
        link.insert(1,value);
    }
    static void get(int k,int index){
        Integer value = link.get(index);
        ans[i++] = value;
        link.insert(1,link.get(index));
        link.del(index);
    }
}
